package com.jtpay.sdk.util;

import android.content.Context;
import android.util.Log;

/**
 * Created by Joe on 2017/5/12 0012 09:33.
 * UncaughtExceptionHandler
 */

public class CrashHandler implements Thread.UncaughtExceptionHandler {

    private static CrashHandler instance;  //single task

    private CrashHandler() {
    }

    public synchronized static CrashHandler getInstance() {  //Synchronize threads
        if (instance == null) {
            instance = new CrashHandler();
        }
        return instance;
    }

    public void init(Context ctx) {  //init
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {  //UncaughtExceptionHandler  deal here
        Log.e("uncaughtException", "uncaughtException, thread: " + thread
                + " name: " + thread.getName() + " id: " + thread.getId() + "exception: "
                + ex);
        /*String threadName = thread.getName();
        Log.d("Sandy", threadName);*/

    }

}
